﻿// CAllUserDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "SaleSystem.h"
#include "CAllUserDlg.h"


// CAllUserDlg

IMPLEMENT_DYNCREATE(CAllUserDlg, CFormView)

CAllUserDlg::CAllUserDlg()
	: CFormView(DIALOG_ALLUSER)
{

}

CAllUserDlg::~CAllUserDlg()
{
}

void CAllUserDlg::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_list);
}

BEGIN_MESSAGE_MAP(CAllUserDlg, CFormView)
END_MESSAGE_MAP()


// CAllUserDlg 诊断

#ifdef _DEBUG
void CAllUserDlg::AssertValid() const
{
	CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void CAllUserDlg::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// CAllUserDlg 消息处理程序


void CAllUserDlg::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	// TODO: 在此添加专用代码和/或调用基类
	m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

	// 初始化表头
	CString field[] = { _T("用户ID"), _T("用户名"), _T("密码"), _T("权限") };
	for (int i = 0; i < sizeof(field) / sizeof(field[0]); ++i)
	{
		m_list.InsertColumn(i, field[i], LVCFMT_CENTER, 90);
	}

	CInfoFile file;
	file.ReadUserline(); //读取用户信息

	//添加数据
	int i = 0;
	CString str;
	for (list<l_user>::iterator it = file.l_ls.begin(); it != file.l_ls.end(); it++)
	{
		str.Format(_T("%d"), it->id);
		m_list.InsertItem(i, str);
		int column = 1;
		m_list.SetItemText(i, column++, (CString)it->name.c_str());
		str.Format(_T("%d"), it->name);
		m_list.SetItemText(i, column++, (CString)it->l_pwd.c_str());
		str.Format(_T("%d"), it->l_pwd);
		str.Format(_T("%d"), it->control);
		m_list.SetItemText(i, column++, str);
		i++;
	}
}
